package com.buba.springcloud.controller;

import com.buba.springcloud.entities.CommonResult;
import com.buba.springcloud.entities.HfRegister;
import com.buba.springcloud.entities.HfStaff;
import com.buba.springcloud.service.HfstafService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/backstagesupporter/main")
public class HfstafController {
    @Resource
    private HfstafService staffService;

    /**
     * 员工查询
     * @param username
     * @param name
     * @return
     */
    @GetMapping("/hfstaff")
    public CommonResult getHfstaff(String username,String name){
        List<HfStaff> staffs=staffService.getHfstaff(username,name);
        if (staffs.size()!=0) {
            return new CommonResult(200,"查询成功",staffs);
        }
        return new CommonResult(500,"查询失败");
    }

    /**
     * 注册
     * @param hfRegister
     * @return
     */
    @PostMapping("/addHfregister")
    public CommonResult addHfregister(@RequestBody HfRegister hfRegister){
        Integer register= staffService.addHfregister(hfRegister);
        if(register > 0){
            return new CommonResult(200,"注册成功",register);
        }
        return new CommonResult(500,"注册失败");
    }

    /**
     * 注册申请
     * @return
     */
    @GetMapping("/hfregister")
    public CommonResult getRegister(){
        List<HfRegister> registers= staffService.getRegister();
        if(registers.size()!=0){
            return new CommonResult(200,"查询成功",registers);
        }
        return new CommonResult(500,"查询失败");
    }

    /**
     * 拒绝申请
     * @param id
     * @return
     */
    @GetMapping("/updRegister")
    public CommonResult updRegister(Integer id){
        Integer register=staffService.updRegister(id);
        if(register > 0){
            return new CommonResult(200,"删除成功",register);
        }
        return new CommonResult(500,"删除失败");
    }

    @GetMapping("/hfRegister")
    public CommonResult hfRegister(Integer id){
        Integer register=staffService.hfRegister(id);
        if (register > 0){
            return new CommonResult(200,"同意申请成功",register);
        }
        return new CommonResult(500,"同意申请失败");
    }
}
